package com.puzzlebazar.client.squaregrid.view;

import com.puzzlebazar.client.util.Vec2i;

public class ComponentHighlighter implements 
	VertexHighlighter, EdgeHighlighter, CellHighlighter {

	final private VertexHighlighter vertexHighlighter;
	final private EdgeHighlighter edgeHighlighter;
	final private CellHighlighter cellHighlighter;
	
	/**
	 * Create an object that is able to highlight components (cells, edges, vertices)
	 * of a square grid.
	 * 
	 * @param vertexHighlighter The highlighter for vertices (can be null)
	 * @param edgeHighlighter The highlighter for edges (can be null)
	 * @param cellHighlighter The highlighter for cells (can be null)
	 */
	public ComponentHighlighter( VertexHighlighter vertexHighlighter,
			EdgeHighlighter edgeHighlighter,
			CellHighlighter cellHighlighter) {
		this.vertexHighlighter = vertexHighlighter;
		this.edgeHighlighter = edgeHighlighter;
		this.cellHighlighter = cellHighlighter;
	}

	@Override
	public void highlightVertex( Vec2i loc ) throws Exception {
		if( vertexHighlighter != null )
			vertexHighlighter.highlightVertex( loc );
	}
	
	@Override
	public void highlightVerticalEdge( Vec2i loc ) throws Exception {
		if( edgeHighlighter != null )
			edgeHighlighter.highlightVerticalEdge( loc );
	}	
	
	@Override
	public void highlightHorizontalEdge( Vec2i loc ) throws Exception {
		if( edgeHighlighter != null )
			edgeHighlighter.highlightHorizontalEdge( loc );
	}	
	
	@Override
	public void highlightCell( Vec2i loc ) throws Exception {
		if( cellHighlighter != null )
			cellHighlighter.highlightCell( loc );
	}

	@Override
	public void highlightCells(Vec2i loc1, Vec2i loc2) throws Exception {
		if( cellHighlighter != null )
			cellHighlighter.highlightCells( loc1, loc2 );
	}

	@Override
	public void unhighlightVertex(Vec2i loc) throws Exception {
		if( vertexHighlighter != null )
			vertexHighlighter.unhighlightVertex( loc );
	}

	@Override
	public void unhighlightVerticalEdge(Vec2i loc) throws Exception {
		if( edgeHighlighter != null )
			edgeHighlighter.unhighlightVerticalEdge( loc );
	}

	@Override
	public void unhighlightHorizontalEdge(Vec2i loc) throws Exception {
		if( edgeHighlighter != null )
			edgeHighlighter.unhighlightHorizontalEdge( loc );
	}

	@Override
	public void unhighlightCell(Vec2i loc) throws Exception {
		if( cellHighlighter != null )
			cellHighlighter.unhighlightCell( loc );
	}

	@Override
	public void unhighlightCells(Vec2i loc1, Vec2i loc2) throws Exception {
		if( cellHighlighter != null )
			cellHighlighter.unhighlightCells( loc1, loc2 );
	}

	/**
	 * Unhighlight all components
	 */
	public void unhilightAll() {
		unhighlightAllVertices();
		unhighlightAllEdges();
		unhighlightAllCells();		
	}

	@Override
	public void unhighlightAllVertices() {
		if( vertexHighlighter != null )
			vertexHighlighter.unhighlightAllVertices();
	}

	@Override
	public void unhighlightAllEdges() {
		if( edgeHighlighter != null )
			edgeHighlighter.unhighlightAllEdges();
	}

	@Override
	public void unhighlightAllCells() {
		if( cellHighlighter != null )
			cellHighlighter.unhighlightAllCells();
	}


}
